<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        /* 
            filter:过滤数组的内容
            需求：找出单词长度大于6的
         */

        const words = ['spray', 'elite', 'exuberant', 'destruction', 'present'];

        //实现方式一
        /*    
         const resultWords=[]
         for(const word of words){
             if(word.length>6){
                 resultWords.push(word)
             }
         }
          console.log(resultWords)
 */

        //实现方式二
  /*       function myFilter2(word) {
            return word.length > 6 ? true : false;
        }
        const resultWords = []
        for (const word of words) {
            if (myFilter2(word)) {
                resultWords.push(word)
            }
        }
        console.log(resultWords)
 */


        //实现方式三
/*         var resultWords = words.filter((word) => {
            // console.log(word);
            return word.length > 6;  //返回的是一个true或false，如果返回true就会保留结果，否则就不会
        })

        console.log(resultWords)
 */

        //参数解析
 /*        const resultWords = words.filter((element,index,arr) => {
            console.log(element);
            console.log(index);
            console.log(arr);
            return element.length > 6;  //返回的是一个true或false，如果返回true就会保留结果，否则就不会
        });
        console.log(resultWords) */


        //终极形式
        const resultWords = words.filter(wold => wold.length>6)
        console.log(resultWords)
    </script>
</head>

<body>

</body>

</html>